//
//  NearbyPhotoViewController.m
//  HappyTrip
//
//  Created by GeminyXC on 15-3-27.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "NearbyPhotoViewController.h"
//自定义显示大图的
#import "NearbyPhotoCollectionViewCell.h"

#import "NearbyPicObject.h"

@interface NearbyPhotoViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain)UICollectionView *collectionView;

@end

@implementation NearbyPhotoViewController

- (void)dealloc
{
    [_collectionView release];
    [super dealloc];
}
//---------------------------------
- (void)viewWillAppear:(BOOL)animated
{
////    self.tabBarController.tabBar.hidden = YES;
////    self.navigationController.navigationBarHidden = YES;
//       self.navigationController.navigationBar.backgroundColor = [UIColor blackColor];
//    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    //    [self.navigationController setHidesBarsOnSwipe:YES];
    //    self.tabBarController.tabBar.alpha = 0;
    self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
    self.tabBarController.tabBar.hidden = YES;
    

}
//---------------------------------
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor blackColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fanhui.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemAction:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor lightGrayColor];
 
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;//水平
    flowLayout.itemSize = CGSizeMake(VIEW_WIDTH, VIEW_HEIGHT);
    flowLayout.minimumInteritemSpacing = 100;//最小列间距
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    flowLayout.minimumLineSpacing = 0;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT + 49 ) collectionViewLayout:flowLayout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.pagingEnabled = YES;
    self.collectionView.backgroundColor = [UIColor blackColor];
    self.collectionView.contentOffset = CGPointMake(self.itemOK * VIEW_WIDTH, 0);//设置偏移量
    [self.view addSubview:_collectionView];
    [_collectionView release];
    
    
    //注册一个cell
    [self.collectionView registerClass:[NearbyPhotoCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    
}

//scrollView已经偏移
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSLog(@"scrollView已经偏移");
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.arrPhoto.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NearbyPhotoCollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    NearbyPicObject *nearbyPicInfo = [self.arrPhoto objectAtIndex:indexPath.item];
    cell.nearbyPicInfo = nearbyPicInfo;
    //把这些放到自定义cell里面
//    cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
////    cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
//    cell.imageView.clipsToBounds = YES;
    return cell;
}

- (void)leftBarButtonItemAction:(UIBarButtonItem *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
